package com.investment.advisor.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Table(name = "trades")
@Getter
@Setter
@NoArgsConstructor
@ToString(exclude = {"portfolio", "fund"})
public class Trade {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "portfolio_id")
    private Portfolio portfolio;  // 所属组合

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fund_id")
    private Fund fund;  // 交易基金

    @Column(nullable = false, length = 20)
    private String action;  // 交易类型：买入、卖出、调仓

    @Column(precision = 20, scale = 2, nullable = false)
    private BigDecimal amount;  // 交易金额

    @Column(precision = 10, scale = 4, nullable = false)
    private BigDecimal price;  // 交易净值

    @Column(precision = 20, scale = 4)
    private BigDecimal shares;  // 交易份额

    @Column(precision = 10, scale = 2)
    private BigDecimal fee;  // 手续费

    @Column(nullable = false)
    private LocalDate tradeDate;  // 交易日期

    @Column(nullable = false, length = 20)
    private String status;  // 状态：处理中、已完成、已取消

    @Column(length = 255)
    private String remark;  // 备注
    
    @Column(length = 50)
    private String creator;  // 创建者

    @CreationTimestamp
    private LocalDateTime createTime;

    @UpdateTimestamp
    private LocalDateTime updateTime;
} 